<?php try{?>
<div id="feedback">
	<a id="feedback-button" href="#" title=""><?php echo $this->translate()->widget('feedback')?></a>
	<div id="feedback-form" class= "modal-box">
		<div class="box-title">
            <div class="wrapper"><h4><?php echo $this->translate()->widget('modal_title'); ?></h4></div>
            <a class="simplemodal-close" href="#"></a>
        </div>
		<div class="box-container">
             <form name="frmFeedBack" id="frmFeedBack" action="<?php echo $this->url(array(), 'mail_mail_feedback'); ?>" method="post">
				<p class="guide"><?php echo $this->translate()->widget('feedback_form_guide')?></p>
				<div class="error-box"><ul></ul></div>
                <div class="field">
                    <label for="feedback-name"><?php echo $this->translate()->widget('feedback_form_name')?></label>
                    <input type="text" size="40" name="feedback[name]" id="feedback-name"/>
                </div>
                
                <div class="field">
                    <label for="feeback-email"><?php echo $this->translate()->widget('feedback_form_email')?></label>
                    <input type="text" size="40" name="feedback[email]" id="feedback-email"/>
                </div>
                <div class="field">
                    <label for="feedback-message"><?php echo $this->translate()->widget('feedback_form_message')?></label>
					<textarea cols="40" rows="8" name="feedback[message]" id="feedback-message"></textarea>
                </div>
                <div class="captcha">
                    <label>&nbsp;</label>
                    <div id="feedback-captcha">
                    </div>
                    <div class="clearfix"></div>
                    
                </div>
                <div class="field submit">
                    <input type="submit" name="feedback" id="btnFeedback" value="<?php echo $this->translate()->widget('feedback_form_submit')?>"/>
                </div>
             </form>
        </div>
	</div>
</div>
<script type="text/javascript">

	$('#feedback-button').click(function(){
		$('#feedback-form').modal({
			containerId: 'feedback-modal',
			onShow: function(){
				Recaptcha.destroy();
				Recaptcha.create("6LdHatASAAAAAJ-O5wIkrQgS7_ofgG2LRMnbKBif", 'feedback-captcha', {
						theme: 'red',
						tabindex: 0,
						callback: Recaptcha.focus_response_field
				});
				$('#frmFeedBack').validate({
					rules:{
						'feedback[name]': {
							required: true
						},
						'feedback[email]' :{
							required: true,
							email: true,
						},
						'feedback[message]': {
							required: true,
							maxlength: 300
						}
					},
					messages:{
						'feedback[name]': {
							required: '<?php echo $this->translate()->widget('feedback_form_name_required')?>'
						},
						'feedback[email]' :{
							required: '<?php echo $this->translate()->widget('feedback_form_email_required')?>',
							email: '<?php echo $this->translate()->widget('feedback_form_email_invalid')?>',
						},
						'feedback[message]': {
							required: '<?php echo $this->translate()->widget('feedback_form_message_required')?>',
							maxlength: '<?php echo $this->translate()->widget('feedback_form_message_max_length')?>'
						}
					},
					errorContainer: "#frmFeedBack .error-box",
					errorLabelContainer: "#frmFeedBack .error-box ul",
					wrapper: "li",
					highlight: function(element, errorClass) {
						$('#feedback-modal').css('height', 'auto');
						$('#frmFeedBack .error-box ul').addClass('error');
						
						$(element).addClass('error');
					}
				});
				
				//ajax submit
				$('#frmFeedBack').submit(function(){
					if($(this).valid()){
						$.ajax({
							url: '<?php echo $this->url(array(), 'mail_mail_feedback')?>',
							dataType: 'json',
							data: {
								name: $('#feedback-name').val(), 
								email: $('#feedback-email').val(), 
								message: $('#feedback-message').val(),
								recaptcha_response_field : $('#recaptcha_response_field').val(),
								recaptcha_challenge_field : $('#recaptcha_challenge_field').val()
							},
							type: 'post',
							beforeSend: function(){
								$('#frmFeedBack .error-box, #frmFeedBack .error-box ul').show();
								$('#frmFeedBack .error-box ul').removeClass('error').addClass('success');
								$('#frmFeedBack .error-box ul').html('').append('<li class="loading"><?php echo $this->translate()->widget('feedback_form_sending')?></li>');
							},
							success: function(response){
								if(response != null){
									$('#frmFeedBack .error-box, #frmFeedBack .error-box ul').show();
									if(response.status){
										$('#frmFeedBack .error-box ul').removeClass('error').addClass('success');
									}else{
										$('#frmFeedBack .error-box ul').removeClass('success').addClass('error');
									}
									$('#frmFeedBack .error-box ul').html('').append('<li>' + response.message + '</li>');
								}
							}
						});
						Recaptcha.reload();
					}
					return false;
				});
			},
			onClose: function(){
				if($('#contact-captcha').length == 1){
					Recaptcha.destroy();
					Recaptcha.create("6LdHatASAAAAAJ-O5wIkrQgS7_ofgG2LRMnbKBif", 'contact-captcha', {
						theme: 'red',
						tabindex: 0,
						callback: Recaptcha.focus_response_field
					});
				}
				$.modal.close();
			}
			
		});
		return false;
	});
</script>
<?php } catch(Exception $ex){echo $ex->getMessage() ;}